package Text31;

import java.util.*;

public class Main {
    static int N = 100010;
    static Range[] ranges = new Range[N];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int st = scanner.nextInt();
        int ed = scanner.nextInt();
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            ranges[i] = new Range(a, b);
        }
        Arrays.sort(ranges, 0, n);
        boolean success = false;//表示成功
        int res = 0;
        for (int i = 0; i < n; i++) {
            int j = i;
            int r_max = (int)-(2e9);
            while (j < n && ranges[j].l <= st) {
                r_max=Math.max(r_max,ranges[j].r);
                j++;
            }
            if(r_max<st){
                break;
            }
            res++;
            if(r_max>=ed){
                success=true;
                break;
            }
            st=r_max;
            i=j-1;
        }
        if(!success) res = -1;
        System.out.println(res);
    }

}

class Range implements Comparable<Range> {
    public int l, r;

    public Range(int l, int r) {
        this.l = l;
        this.r = r;
    }

    @Override
    public int compareTo(Range o) {
        return Integer.compare(l, o.l);
    }
}